var ctx = ctx;
var patientId=$("#patientId").val();
var patVisitId=$("#patVisitId").val();
var bedId=$("#bedRecId").val();
$(function () {
   // loadDiv('leaveHospPatientListDiv', ctx + '/nurse/wardCirculation/findWaitLeaveHospPatientList');
    return loadDiv('leaveHospForm', ctx + '/nurse/wardCirculation/findInfoByLeaveHospParam?patientId=' + patientId + '&patVisitId=' + patVisitId + '&bedRecId=' + bedId);
});

function showLeaveHospForm(patientId, patVisitId, bedId) {
    $("#leaveHospPatientListDiv").attr("class", "col-lg-8");
    $("#leaveHospForm").show('normal');
    hideShowTableTd("leaveHospPatientListDiv", '3,5,6', '2');
    return loadDiv('leaveHospForm', ctx + '/nurse/wardCirculation/findInfoByLeaveHospParam?patientId=' + patientId + '&patVisitId=' + patVisitId + '&bedRecId=' + bedId);
}

function closeLeaveHospForm() {
    $("#leaveHospPatientListDiv").attr("class", "col-lg-12");
    $("#leaveHospPatientListDiv").show('normal');
    hideShowTableTd("leaveHospPatientListDiv", '3,5,6', '1');
    $("#leaveHospForm").attr("style", "display: none");
}


function formLeaveHospLoad(divId, formId, url, hrefUrl,patientId,visitId) {
    if (flag) {
        /*判断病人是否有包床，如果有包床，解除包床后再取消移入*/
        $.ajax({
            type: "POST",
            url: ctx+"/nurse/bedRec/validBedOccupy?patientId="+patientId+"&visitId="+visitId,
            dataType: "json",
            success: function (data) {
                if (data.code == "success") {
                    if ($('#' + formId).parsley().validate()) {
                        flag = false;
                        $("#" + formId + " input,#" + formId + " select").removeAttr("disabled");
                        $.ajax({
                            type: "POST",
                            data: $("#" + formId).serialize(),
                            url: url,
                            dataType: "json",
                            success: function (data) {
                                // alert(data.code);
                                if (data.code == "1" || data.code == 1) {
                                    if (data.data != null && data.data != '') {
                                        var datas = eval(data.data);
                                        for (var i = 0; i < datas.length; i++) {
                                            if (datas[i].results == "1") {
                                                toastr.info(datas[i].message);
                                            }
                                        }
                                    }

                                } else if (data.code == 0 || data.code == '0') {
                                    // loadDiv(divId,hrefUrl);
                                    toastr.success('病人出院成功');
                                    parent.layer.closeAll();
                                    parent.refesh();
                                } else {
                                    flag = true;
                                    toastr.error(data.data);
                                }
                            },
                            error: function (data) {
                                toastr.error('网络连接错误,请检查网络');
                                flag = true;
                            }
                        });
                    }
                } else if (data.code == "info") {
                    toastr.info(data.data);
                } else {
                    toastr.error("病人出院失败");
                }
            },
            error: function (data) {
                toastr.error('网络连接错误,请检查网络');
            }
        });


    }
    return false;
}